package com.example.runningman.database;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import com.example.runningman.dao.PointsDao;
import com.example.runningman.dao.StepsDao;
import com.example.runningman.bean.BaiduPoints;
import com.example.runningman.bean.Steps;

@Database(entities = {BaiduPoints.class, Steps.class},version = 1,exportSchema = false)
public abstract class BaiduPointsDatebase extends RoomDatabase {
    private static BaiduPointsDatebase INSTANCE;
    private static final Object sLock = new Object();
    public abstract PointsDao getPointsDao();
    public abstract StepsDao StepsDao();
    public static BaiduPointsDatebase getInstance(Context context) {   //单例模式
        synchronized (sLock) {
            if (INSTANCE == null) {
                INSTANCE =
                        Room.databaseBuilder(context.getApplicationContext(), BaiduPointsDatebase.class, "points.db")
                                .allowMainThreadQueries()
                                .build();
            }
            return INSTANCE;
        }
    }
}
